package com.jaks.xpense.data;

import java.util.ArrayList;

import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;

import com.jaks.xpense.data.entities.PaymentType;
import com.jaks.xpense.data.entities.TableEntity;

public class PaymentTypes extends Table {

	private static final String[] Columns = new String[] { TableEntity.Id, PaymentType.Name };

	public PaymentTypes(Context context) throws SQLException {
		super(context);
	}

	@Override
	public long create(TableEntity entity) {
		return 0;
	}

	@Override
	public boolean update(TableEntity entity) {
		return false;
	}

	@Override
	public boolean delete(long id) {
		return false;
	}

	@Override
	public Cursor readAll() {
		return db.query(PaymentType.TableName, Columns, null, null, null, null, null);
	}

	@Override
	public TableEntity read(long id) throws SQLException {
		return null;
	}

	public ArrayList<PaymentType> readAllToList() throws SQLException {

		ArrayList<PaymentType> tags = new ArrayList<PaymentType>();
		Cursor cursor = db.query(true, PaymentType.TableName, Columns, null, null, null, null, null,
		    null);

		if (cursor.moveToFirst()) {

			do {
				PaymentType entity = new PaymentType();
				entity.setId(cursor.getLong(cursor.getColumnIndex(TableEntity.Id)));
				entity.setName(cursor.getString(cursor.getColumnIndex(PaymentType.Name)));

				tags.add(entity);
			} while (cursor.moveToNext());
		}

		if (cursor != null && !cursor.isClosed()) {
			cursor.close();
		}

		return tags;
	}
}
